<!DOCTYPE html>
<html>
<head>
    <title>组件的嵌套</title>
     <script src="../js/vue.min.js"></script> 
</head>
<body>
    <!-- Your HTML code goes here -->
    <div id="root">
        <!-- <app></app> -->
    </div>
</body>
<script>

    const student = {  //简写
        name: 'student',// 组件名, 也可以不写, 只能在开发者工具中看到
        // 记得要有div包裹
        template:`
            <div> 
                <h2>学生姓名: {{name}}</h2>
                <h2>学生年龄: {{age}}</h2>
            </div>
        `,
        data() { //组件中的data必须是函数
            return {
                name: '张三',
                age: 182
            }
        }
    }

    const school={
        name: 'school',
        template:`
            <div>
                <h2>学校名称: {{name}}</h2>
                <h2>学校地址: {{address}}</h2>
                <hr></hr>
                <student></student>
            </div>
        `,
        data(){
            return {
                name: '清华大学2',
                address: '北京市海淀区'
            }
        },
        components: {
            student
        }
    }

    const app={
        template:`
            <div>
                <school></school>
            </div>
        `,
        components: {
            school
        }
    }

    const vm = new Vue({
        template:`
            <div>
                <app></app>
            </div>
        `,
        el: "#root",
        // 局部注册组件
        components: {
            app
        }
    })

</script>
</html>
